home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / ImageMap.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  3.1 KB  |  144 lines

  1. package symantec.itools.multimedia;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Event;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.Rectangle;
  9. import java.awt.Toolkit;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12. import java.util.Vector;
  13.  
  14. public class ImageMap extends ImageViewer {
  15.    protected Vector rects;
  16.    private int rectCount;
  17.    private boolean showrect;
  18.    private ImageMapRect lastrect;
  19.  
  20.    public ImageMap() {
  21.       this(true);
  22.    }
  23.  
  24.    public ImageMap(boolean var1) {
  25.       this.rectCount = 0;
  26.       this.rects = new Vector();
  27.       this.showrect = var1;
  28.    }
  29.  
  30.    public ImageMap(boolean var1, String var2) throws MalformedURLException {
  31.       this(var1, new URL(var2));
  32.    }
  33.  
  34.    public ImageMap(boolean var1, URL var2) throws MalformedURLException {
  35.       this(var1, Toolkit.getDefaultToolkit().getImage(var2));
  36.    }
  37.  
  38.    public ImageMap(boolean var1, Image var2) throws MalformedURLException {
  39.       super(var2);
  40.       this.rectCount = 0;
  41.       this.rects = new Vector();
  42.       this.showrect = var1;
  43.    }
  44.  
  45.    public void setShowrect(boolean var1) {
  46.       this.showrect = var1;
  47.    }
  48.  
  49.    public boolean getShowrect() {
  50.       return this.showrect;
  51.    }
  52.  
  53.    public boolean addRect(int var1, int var2, int var3, int var4) {
  54.       ImageMapRect var5 = new ImageMapRect(var1, var2, var3, var4);
  55.       if (!this.overlap(var5)) {
  56.          var5.visible = false;
  57.          this.rects.addElement(var5);
  58.          ++this.rectCount;
  59.          return true;
  60.       } else {
  61.          return false;
  62.       }
  63.    }
  64.  
  65.    public boolean addRect(ImageMapRect var1) {
  66.       if (!this.overlap(var1)) {
  67.          var1.visible = false;
  68.          this.rects.addElement(var1);
  69.          ++this.rectCount;
  70.          return true;
  71.       } else {
  72.          return false;
  73.       }
  74.    }
  75.  
  76.    public ImageMapRect findRect(int var1, int var2) {
  77.       Object var4 = null;
  78.  
  79.       for(int var3 = 0; var3 < this.rects.size(); ++var3) {
  80.          ImageMapRect var5 = (ImageMapRect)this.rects.elementAt(var3);
  81.          if (((Rectangle)var5).inside(var1, var2)) {
  82.             return var5;
  83.          }
  84.       }
  85.  
  86.       return null;
  87.    }
  88.  
  89.    public boolean overlap(ImageMapRect var1) {
  90.       byte var2 = 0;
  91.       if (var2 >= this.rects.size()) {
  92.          return false;
  93.       } else {
  94.          ImageMapRect var3 = (ImageMapRect)this.rects.elementAt(var2);
  95.          return ((Rectangle)var1).intersects(var3);
  96.       }
  97.    }
  98.  
  99.    public boolean mouseMove(Event var1, int var2, int var3) {
  100.       if (this.showrect) {
  101.          ImageMapRect var4 = this.findRect(var2, var3);
  102.          if (var4 != null && !var4.visible) {
  103.             Graphics var6 = ((Component)this).getGraphics();
  104.             var6.setXORMode(Color.red);
  105.             var6.drawRect(var4.x, var4.y, var4.width, var4.height);
  106.             var4.visible = true;
  107.             this.lastrect = var4;
  108.             return true;
  109.          }
  110.  
  111.          if (this.lastrect != null && var4 == null && this.lastrect.visible) {
  112.             Graphics var5 = ((Component)this).getGraphics();
  113.             var5.setXORMode(Color.red);
  114.             var5.drawRect(this.lastrect.x, this.lastrect.y, this.lastrect.width, this.lastrect.height);
  115.             this.lastrect.visible = false;
  116.             return true;
  117.          }
  118.       }
  119.  
  120.       return super.mouseMove(var1, var2, var3);
  121.    }
  122.  
  123.    public boolean mouseDown(Event var1, int var2, int var3) {
  124.       ImageMapRect var4 = this.findRect(var2, var3);
  125.       if (var4 == null) {
  126.          return super.mouseDown(var1, var2, var3);
  127.       } else {
  128.          this.lastrect = var4;
  129.          return true;
  130.       }
  131.    }
  132.  
  133.    public boolean mouseUp(Event var1, int var2, int var3) {
  134.       ImageMapRect var4 = this.findRect(var2, var3);
  135.       if (var4 != null && var4 == this.lastrect) {
  136.          Event var5 = new Event(var4, 1001, (Object)null);
  137.          ((Component)this).postEvent(var5);
  138.          return true;
  139.       } else {
  140.          return super.mouseUp(var1, var2, var3);
  141.       }
  142.    }
  143. }
  144.